/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.tabs.results.background;

import java.awt.Frame;
import javax.swing.JDialog;
import systole.domain.persons.Patient;
import systole.domain.report.Report;
import systole.exceptions.ExceptionDAO;
import systole.persistence.FacadeDB;
import systole.view.messages.EntityDescriptions;
import systole.view.tabs.results.ResultDialogController;

/**
 *
 * @author jmj
 */
public class ControllerBackground extends ResultDialogController {

    private Patient patient;

    /**
     * 
     * @param patient
     */
    public ControllerBackground(Patient patient) {
        super();
        this.patient = patient;
    }

    @Override
    protected void initFormsControls() throws ExceptionDAO {
        JDialogBackground background = (JDialogBackground) this.form;
        background.loadPathologiesPanel(new JPnlBackgroundTable(FacadeDB.getInstance().getPathologyByPatienBroker().getAllPatientPathologies(this.patient), EntityDescriptions.PATHOLOGIES));
        background.loadFamilyPanel(new JPnlBackgroundTable(FacadeDB.getInstance().getFamilyBackgroundBroker().getAllFamilyPatientBackground(this.patient), EntityDescriptions.FAMILY_PLURAL));
        background.loadMedicinesPanel(new JPnlBackgroundTable(FacadeDB.getInstance().getMedicineByPatientBroker().getAllPatientMedicines(this.patient), EntityDescriptions.MEDICINES));
        background.loadSurgeriesPanel(new JPnlBackgroundTable(FacadeDB.getInstance().getSurgeryByPatientBroker().getAllPatientSurgeries(this.patient), EntityDescriptions.SURGERIES));
    }

    @Override
    protected JDialog createForm(Frame parent) {
        return new JDialogBackground(parent, this);
    }

    @Override
    protected void loadIconOnForm() {
    }

    @Override
    protected void loadReportOnForm(Report report) {
        JDialogBackground background = (JDialogBackground) this.form;
        background.getFamilyJPnlBackgroundTable().loadData(report.getBackgroundFamily());
        background.getSurgeriesJPnlBackgroundTable().loadData(report.getBackgroundSurgeries());
        background.getPathologiesJPnlBackgroundTable().loadData(report.getBackgroundPathologies());
        background.getMedicinesJPnlBackgroundTable().loadData(report.getBackgroundMedicines());
    }

    @Override
    protected void loadReportFromForm() {
        JDialogBackground background = (JDialogBackground) this.form;
        this.reportModel.updateBackground(background.getSurgeriesJPnlBackgroundTable().getPatientBackground(),
                background.getFamilyJPnlBackgroundTable().getPatientBackground(),
                background.getPathologiesJPnlBackgroundTable().getPatientBackground(),
                background.getMedicinesJPnlBackgroundTable().getPatientBackground(),
                null);
    }
}
